//
//  OrderDetailGuestMessageCell.m
//  danpin
//
//  Created by chuangjia on 9/11/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "OrderDetailGuestMessageCell.h"

@interface OrderDetailGuestMessageCell()
{
    
}
@property (nonatomic, strong) UIView *bgView;
@property(nonatomic,strong)RTLabel *skuNameLabel;
@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UIImageView *lineView;
@end


@implementation OrderDetailGuestMessageCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _bgView = [[UIView alloc] initWithFrame:CGRectZero];
        _bgView.backgroundColor =[UIColor clearColor];
        [self.contentView addSubview:_bgView];
        //
        _skuNameLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _skuNameLabel.backgroundColor = [UIColor clearColor];
        _skuNameLabel.textColor = CONTEXT_COLOR;
        _skuNameLabel.textAlignment = NSTextAlignmentLeft;
        _skuNameLabel.font = FONT(12);
        _skuNameLabel.lineSpacing = LSpacing;
        
        [_bgView addSubview:_skuNameLabel];
        
        _timeLabel =[[UILabel alloc] initWithFrame:CGRectZero];
        _timeLabel.backgroundColor = [UIColor clearColor];
        _timeLabel.textColor =UIColorFromRGB(0xcccccc);
        _timeLabel.textAlignment = NSTextAlignmentRight;
        _timeLabel.font = FONT(12);
        [_bgView addSubview:_timeLabel];
        _lineView =[[UIImageView alloc] initWithFrame:CGRectZero];
        _lineView.backgroundColor=UIColorFromRGB(0xe5e5e5);
        [self.contentView addSubview:_lineView];
    }
    return self;
}
-(void)dealloc
{
    self.actionBlock=nil;
    self.data=nil;
    self.indexPath=nil;
    self.key=nil;
    self.other=nil;
    
    [self.skuNameLabel removeFromSuperview];
    self.skuNameLabel=nil;
    [self.timeLabel removeFromSuperview];
    self.timeLabel =nil;
    
    [self.bgView removeFromSuperview];
    self.bgView=nil;
    
    
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _bgView.frame =CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    self.lineView.frame =CGRectMake(0,self.bounds.size.height-0.5, DEVICE_WIDTH, 0.5);
}
- (void)drawRect:(CGRect)rect {
    
    [super drawRect:rect];
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model other:(id)other key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.other =other;
    self.key =key;
    self.data =model;
    [self showInfo:model indexPath:indexPath];
}
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key = key;
    self.data =model;
    [self showInfo:model indexPath:indexPath];
}
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dict =(NSDictionary*)model;
    self.data =model;
    self.indexPath=indexPath;
    float fTop = 0;
    fTop += PHOTO_FRAME_WIDTH;
    
    //
    NSString *skuname =[dict stringForKey:@"message" withDefaultValue:@""];
    if (skuname.length>0) {
        [_skuNameLabel setText:[NSString stringWithFormat:@"%@",skuname]];
        CGSize optimumSize = [_skuNameLabel optimumSize];
        CGFloat hh =optimumSize.height;
        if (hh<20) {
            hh=20;
        }
        _skuNameLabel.frame = CGRectMake(PHOTO_FRAME_WIDTH,fTop, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, hh);
        
        fTop = fTop+hh+PHOTO_FRAME_WIDTH;
    }
    NSString *timestr =[dict stringForKey:@"add_time" withDefaultValue:@""];
    _timeLabel.frame = CGRectMake(PHOTO_FRAME_WIDTH,fTop, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, PHOTO_FRAME_WIDTH*2);
    _timeLabel.text =timestr;
    [self layoutSubviews];
}


/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    NSDictionary *dict =(NSDictionary*)model;
    NSString *skuname =[dict stringForKey:@"message" withDefaultValue:@""];
    CGFloat hight =PHOTO_FRAME_WIDTH;
    if (skuname.length>0) {
        RTLabel *text1Label =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        text1Label.font = FONT(12);
        text1Label.lineSpacing = LSpacing;
        [text1Label setText:[NSString stringWithFormat:@"%@",skuname]];
        CGSize optimumSize = [text1Label optimumSize];
        text1Label=nil;
        CGFloat hh1 =optimumSize.height;
        
        hight = hight +hh1+PHOTO_FRAME_WIDTH;
    }
    
    return hight+PHOTO_FRAME_WIDTH*3;
    
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
-(void)bangdanAction
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_recommendTobangdan,self,self.data,self.key,self.indexPath);
    }
}
@end
